import useUserStore from "@/utils/stores/modules/user"

export default {
    mounted: (el: HTMLElement, binding: any) => {
        const { value } = binding
        const userStore = useUserStore()
        const permissions = userStore.permissions
        const all_permission = '*'

        if (value && Array.isArray(value)) {
            if (value.length > 0) {
                const hasPermission = permissions.some((permission: string) => {
                    return all_permission === permission || value.includes(permission)
                })

                if (!hasPermission) {
                    el.parentNode && el.parentNode.removeChild(el)
                }
            }
        } else {
            throw new Error('like v-perms="[\'auth.menu/edit\']"')
        }
    }
}
